<template>
	<view>
		 <h2>个人中心演示</h2>
		<button class="logout-btn" @click="logout" type="default">退出登录</button>
	</view>
</template>

<script>
	// import {mapState} from 'vuex'
	import api from '@/api/api.js'
	export default {
		data() {
			return {
				token:{}
			}
		},
		onShow() {
			this.token=uni.getStorageSync('token')
		},
		onLoad() {
			// this.$util.isLogin()
		},
		
		computed: {
			// ...mapState(['userInfo'])
		},
		
		methods: {
			//退出
			logout() {
				uni.showModal({
					title: '确定退出登录?',
					content: '退出后不会删除任何历史数据',
					success: async (res) => {
					
						if(res.confirm) {
							 let res = await api.loginout()
							console.log(res)
							if(res.code === 20000) {
								//退出成功
								this.$util.msg('成功退出登录')
								uni.removeStorageSync('token')//删除存储的token
								uni.removeStorageSync('userinfo')//删除存储的用户信息
								setTimeout(() => {
									uni.navigateBack({
										delta:1
									})
								}, 300)
							}else {
								this.$util.msg(message)
							}
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	
</style>
